"""
主题: 在类上强制使用编程规约
问题: 你的程序包含一个很大的类继承体系，你希望强制执行某些编程规约（或者代码诊断）来帮助程序员保持清醒。
提示 : 
"""

class MyMeta(type):
    '''有两种方式'''
    # def __new__(self, clsname, bases, clsdict):
        # clsname is name of class being defined
        # bases is tuple of base classes
        # clsdict is class dictionary
        # return super().__new__(self, clsname, bases, clsdict)
    
    def __init__(self, clsname, bases, clsdict):
        super().__init__(clsname, bases, clsdict)
        # clsname is name of class being defined
        # bases is tuple of base classes
        # clsdict is class dictionary 

class NoMixedCaseMeta(type):
    '''拒绝任何有混合大小写名字作为方法的类定义'''
    def __new__(cls, clsname, bases, clsdict):
        for name in clsdict:
            if name.lower() != name:
                raise TypeError('Bad attribute name: ' + name)
        return super().__new__(cls, clsname, bases, clsdict)

class Root(metaclass=NoMixedCaseMeta):
    pass

class A(Root):
    def foo_bar(self): # Ok
        pass

class B(Root):
    value1 = 'value1'
    def fooBar(self): # TypeError
        pass

if __name__ == '__main__':
    print('main')     